package com.atzxh.datastructure.sort;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 小红同学
 * @create 2022-10-14-20:44
 * @description
 */
@SuppressWarnings({"all"})
public class SelectSort {
    public static void main(String[] args) {
        int[] arr = new int[80000];
        for (int i = 0; i < 80000; i++) {
            arr[i] = (int) (Math.random() * 800000);
        }

        // 开始计时
        Date start = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String start_str = simpleDateFormat.format(start);
        System.out.println("开始时间：" + start_str);

        selectSort(arr);

        // 计时结束
        Date end = new Date();
        String end_str = simpleDateFormat.format(end);
        System.out.println("结束时间：" + end_str);

    }

    //选择排序
    public static void selectSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < arr.length; j++) {
                if (min > arr[j]) {
                    min = arr[j];
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
        }
    }
}
